
using StudentVideo.Common.Models;

namespace StudentVideo.Extensions;

/// <summary>
/// HttpContext 扩展
/// </summary>
public static class HttpContextExtensions {

   private static readonly string _currentUserKey = "CurrentUser";

   public static CurrentUser? GetUserData(this HttpContext context) {
      if (context.Items.TryGetValue("CurrentUser", out var value) && value is CurrentUser currentUser)
         return currentUser;

      return null;
   }

   public static void SetUserData(this HttpContext context, CurrentUser currentUser) {
      context.Items[_currentUserKey] = currentUser;
   }
}
